/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package avl.sv.server.slides;

import avl.sv.server.PropertiesManager;
import java.util.Date;

public class UploadAuth{
    final String slideSetName, fileName, uploadToken;
    private final Date revokerAfter;
    public UploadAuth(String slideSetName, String fileName) {
        this.slideSetName = slideSetName;
        this.fileName = fileName;
        this.uploadToken = createUploadToken();
        this.revokerAfter = new Date(new Date().getTime()+PropertiesManager.getUploadTimeoutMinutes()*60*1000);
    }

    public boolean isExpired(){
        return revokerAfter.before(new Date());
    }
    
    private String createUploadToken() {
        return Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE))
                + Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE))
                + Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE))
                + Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE));
    }    
}